package com.cskaoyan.service.wx_order;

import com.cskaoyan.bean.wx_newOrder.MarketOrder;
import com.cskaoyan.mapper.wx_newOrder.NewMarketOrderMapper;

import com.cskaoyan.bean.wx_newOrder.MarketOrderGoods;
import com.cskaoyan.mapper.wx_newOrder.NewMarketOrderGoodsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: Jason 805636901@qq.com
 * @create: 2021-10-24-6:10 PM
 */
@Service
public class WxOrderServicePartBImpl implements WxOrderServicePartB{
    @Autowired
    NewMarketOrderMapper newMarketOrderMapper;
    @Autowired
    NewMarketOrderGoodsMapper newMarketOrderGoodsMapper;


        @Override
        public int confirm(Integer orderId) {
            MarketOrder marketOrder = newMarketOrderMapper.selectByPrimaryKey(orderId);
            int status = (int) marketOrder.getOrderStatus();
            if (status == 301) {
                //设置comments订单 查找订单里的商品数和
                int commentNum = newMarketOrderGoodsMapper.countCommentByOrderId(orderId);
                newMarketOrderMapper.orderConfrimById(orderId,commentNum);
                newMarketOrderGoodsMapper.updateCommonByOrderId(orderId);
                return 1;
            }
            return 0;
        }

    @Override
    public MarketOrderGoods goods(Integer orderId, Integer goodsId) {
        MarketOrderGoods marketOrderGoods = newMarketOrderGoodsMapper.orderGoods(orderId, goodsId);
        return marketOrderGoods;
    }

    @Override
    public int refund(Integer orderId) {
        MarketOrder marketOrder = newMarketOrderMapper.selectByPrimaryKey(orderId);
        int status = (int) marketOrder.getOrderStatus();
        if (status == 201) {
            newMarketOrderMapper.orderRefundById(orderId);
            return 1;
        }
        return 0;
    }

    @Override
    public int delete(Integer orderId) {

        MarketOrder marketOrder = newMarketOrderMapper.selectByPrimaryKey(orderId);
        int status = (int) marketOrder.getOrderStatus();
        if (status == 102 || status == 103 || status == 203) {

            newMarketOrderMapper.deleteByOrderIdInLogic(orderId);
            newMarketOrderGoodsMapper.deleteOrderGoodsByOrderIdInLogic(orderId);
            return 1;
        }
        return 0;
    }


}
